package com.jinmdz.fmis.api.api.controller;

import com.jinmdz.fmis.api.api.service.SearchService;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.core.model.SearchListData;
import com.jinmdz.fmis.core.model.SearchLoadData;
import com.jinmdz.fmis.dao.model.search.*;
import com.jinmdz.fmis.dao.model.search.businessoverview.BusinessOverviewItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 查询相关接口
 *
 * @author GuanKui
 * @date 2020/2/24 13:41
 */
@Api(description = "查询相关接口")
@RestController()
@RequestMapping("/api/search")
public class SearchController extends BaseController {

    @Resource
    private SearchService searchService;

    /**
     * 火化档案（逝者）信息查询
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  13:43
     */
    @ApiOperation(value = "火化档案（逝者）信息查询", notes = "根据业务编码、逝者姓名、家属姓名、承办人/单位、到馆日期条件查询逝者信息")
    @PostMapping("/load-cremation-archives")
    public BaseResult<SearchLoadData<SearchCremationArchivesViewItem>> loadCremationArchives(@RequestBody SearchCremationArchivesData data) {
        return resultHandler(data, userItem -> searchService.loadCremationArchives(data));
    }

    /**
     * 火化档案（逝者）信息导出Excel
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  13:43
     */
    @ApiOperation(value = "火化档案（逝者）信息导出Excel", notes = "根据业务编码、逝者姓名、家属姓名、承办人/单位、到馆日期条件查询逝者信息"
            , produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @PostMapping("/load-cremation-archives-export-excel")
    public void loadCremationArchivesExportExcel(@RequestBody SearchCremationArchivesData data) {
        searchService.loadCremationArchivesExportExcel(data);
    }

    /**
     * 冷藏业务查询
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  16:54
     */
    @ApiOperation(value = "冷藏业务查询", notes = "根据业务编码、逝者姓名、冷藏日期条件查询逝者冷藏业务信息")
    @PostMapping("/load-cold-storage")
    public BaseResult<SearchLoadData<SearchColdStorageViewItem>> loadColdStorage(@RequestBody SearchColdStorageData data) {
        return resultHandler(data, userItem -> searchService.loadColdStorage(data));
    }

    /**
     * 冷藏业务查询导出Excel
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  16:54
     */
    @ApiOperation(value = "冷藏业务查询导出Excel", notes = "根据业务编码、逝者姓名、冷藏日期条件查询逝者冷藏业务信息"
            , produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @PostMapping("/load-cold-storage-export-excel")
    public void loadColdStorageExportExcel(@RequestBody SearchColdStorageData data) {
        searchService.loadColdStorageExportExcel(data);
    }

    /**
     * 礼厅业务查询
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  16:54
     */
    @ApiOperation(value = "礼厅业务查询", notes = "根据业务编码、逝者姓名、礼厅分类、用厅日期条件查询逝者礼厅业务信息")
    @PostMapping("/load-mourn-ceremony")
    public BaseResult<SearchLoadData<SearchMournCeremonyViewItem>> loadMournCeremony(@RequestBody SearchMournCeremonyData data) {
        return resultHandler(data, userItem -> searchService.loadMournCeremony(data));
    }

    /**
     * 礼厅业务查询导出Excel
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  16:54
     */
    @ApiOperation(value = "礼厅业务查询导出Excel", notes = "根据业务编码、逝者姓名、礼厅分类、用厅日期条件查询逝者礼厅业务信息"
            , produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @PostMapping("/load-mourn-ceremony-export-excel")
    public void loadMournCeremonyExportExcel(@RequestBody SearchMournCeremonyData data) {
        searchService.loadMournCeremonyExportExcel(data);
    }

    /**
     * 火化数据查询
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/25  17:33
     */
    @ApiOperation(value = "火化数据查询", notes = "返回指定查询分页结果信息，包括业务编码，逝者姓名、逝者性别、逝者年龄、逝者证件号码、火化炉型、火化证号、火化日期数据")
    @PostMapping("/load-cremation-data")
    public BaseResult<SearchLoadData<SearchCremationDataViewItem>> loadCremationData(@RequestBody SearchCremationData data) {
        return resultHandler(data, userItem -> searchService.loadCremationData(data));
    }

    /**
     * 火化数据查询导出Excel
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/25  17:33
     */
    @ApiOperation(value = "火化数据查询导出Excel", notes = "返回指定查询分页结果信息，包括业务编码，逝者姓名、逝者性别、逝者年龄、逝者证件号码、火化炉型、火化证号、火化日期数据"
            , produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @PostMapping("/load-cremation-data-export-excel")
    public void loadCremationDataExportExcel(@RequestBody SearchCremationData data) {
        searchService.loadCremationDataExportExcel(data);
    }

    /**
     * 火化台账查询
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  16:54
     */
    @ApiOperation(value = "火化台账查询", notes = "根据火化预约日期条件查询火化台账信息，火化台账中只统计逝者火化类型(逝者表funeral_dead中cremation_type_code字段)" +
            "（字典:cremation_type）为遗体的数据")
    @PostMapping("/load-cremation-ledger")
    public BaseResult<SearchLoadData<SearchCremationLedgerViewItem>> loadCremationLedger(@RequestBody SearchCremationLedgerData data) {
        return resultHandler(data, userItem -> searchService.loadCremationLedger(data));
    }

    /**
     * 火化台账查询导出Excel
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  16:54
     */
    @ApiOperation(value = "火化台账查询导出Excel", notes = "根据火化预约日期条件查询火化台账信息，火化台账中只统计逝者火化类型(逝者表funeral_dead中cremation_type_code字段)" +
            "（字典:cremation_type）为遗体的数据", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @PostMapping("/load-cremation-ledger-export-excel")
    public void loadCremationLedgerExportExcel(@RequestBody SearchCremationLedgerData data) {
        searchService.loadCremationLedgerExportExcel(data);
    }

    /**
     * 费用查询
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  16:54
     */
    @ApiOperation(value = "费用查询", notes = "根据业务编码、逝者姓名、项目名称、结算日期条件查询费用信息")
    @PostMapping("/load-charge-query")
    public BaseResult<SearchLoadData<SearchChargeViewItem>> loadChargeQuery(@RequestBody SearchChargeData data) {
        return resultHandler(data, userItem -> searchService.loadChargeQuery(data));
    }

    /**
     * 费用查询导出Excel
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  16:54
     */
    @ApiOperation(value = "费用查询导出Excel", notes = "根据业务编码、逝者姓名、项目名称、结算日期条件查询费用信息"
            , produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @PostMapping("/load-charge-query-export-excel")
    public void loadChargeQueryExportExcel(@RequestBody SearchChargeData data) {
        searchService.loadChargeQueryExportExcel(data);
    }

    /**
     * 优惠惠民统计
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  16:54
     */
    @ApiOperation(value = "优惠惠民统计", notes = "返回指定查询分页结果信息，包括业务编码、逝者姓名、逝者性别、逝者年龄、证件号码、惠民区域、减免类型、" +
            "优惠金额，惠民金额、户籍地、火化日期数据")
    @PostMapping("/load-huimin-reduction")
    public BaseResult<SearchLoadData<SearchHuiMinViewItem>> loadHuiMinReduction(@RequestBody SearchHuiMinData data) {
        return resultHandler(data, userItem -> searchService.loadHuiMinReduction(data));
    }

    /**
     * 优惠惠民统计导出Excel
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  16:54
     */
    @ApiOperation(value = "优惠惠民统计导出Excel", notes = "返回指定查询结果信息，包括业务编码、逝者姓名、逝者性别、逝者年龄、证件号码、惠民区域、减免类型、" +
            "优惠金额，惠民金额、户籍地、火化日期数据"
            , produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @PostMapping("/load-huimin-reduction-export-excel")
    public void loadHuiminReductionExportExcel(@RequestBody SearchHuiMinData data) {
        searchService.loadHuiMinReductionExportExcel(data);
    }

    /**
     * 殡仪馆收入统计
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  16:54
     */
    @ApiOperation(value = "殡仪馆收入统计", notes = "根据结算日期段查询殡仪馆收入信息")
    @PostMapping("/load-revenue-statistics")
    public BaseResult<SearchListData> loadRevenueStatistics(@RequestBody SearchRevenueStatisticsData data) {
        return resultHandler(data, userItem -> searchService.loadRevenueStatistics(data));
    }

    /**
     * 殡仪馆收入统计导出Excel
     *
     * @param data 查询条件
     * @return
     * @author GuanKui
     * @date 2020/2/24  16:54
     */
    @ApiOperation(value = "殡仪馆收入统计导出Excel", notes = "根据结算日期段查询殡仪馆收入信息", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @PostMapping("/load-revenue-statistics-export-excel")
    public void loadRevenueStatisticsExportExcel(@RequestBody SearchRevenueStatisticsData data) {
        searchService.loadRevenueStatisticsExportExcel(data);
    }

    /**
     * 殡仪馆数据总览
     *
     * @return
     * @author GuanKui
     * @date 2020/2/27  8:50
     */
    @ApiOperation(value = "殡仪馆数据总览", notes = "返回最近30天内到馆遗体数量、冷柜实时数据、礼厅实时数据、火化炉概况")
    @PostMapping("/load-business-overview")
    public BaseResult<BusinessOverviewItem> loadBusinessOverview() {
        return searchService.loadBusinessOverview();
    }

    /**
     * 系统操作日志查询
     *
     * @param data 查询条件
     * @return
     * @author LiCongLu
     * @date 2020-04-20 15:25
     */
    @ApiOperation(value = "系统操作日志查询", notes = "根据业务编码、员工姓名、日志内容、操作时间条件查询操作日志信息")
    @PostMapping("/load-system-operation-log")
    public BaseResult<SearchLoadData<SearchOperationLogViewItem>> loadSystemOperationLog(@RequestBody SearchOperationLogData data) {
        return resultHandler(data, userItem -> searchService.loadSystemOperationLog(data));
    }

    /**
     * 系统操作日志查询导出Excel
     *
     * @param data 查询条件
     * @return
     * @author LiCongLu
     * @date 2020-04-20 15:26
     */
    @ApiOperation(value = "系统操作日志查询导出Excel", notes = "根据业务编码、员工姓名、日志内容、操作时间条件查询操作日志信息"
            , produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @PostMapping("/load-system-operation-log-export-excel")
    public void loadSystemOperationLogExportExcel(@RequestBody SearchOperationLogData data) {
        searchService.loadSystemOperationLogExportExcel(data);
    }

}
